"""
文件压缩打包
"""

import os
import zipfile

from my_typing import *


def zip_directory(
    directory: PathOrStr,
    zip_file_path: PathOrStr,
) -> None:
    """
    将指定目录下的所有文件压缩成 zip 格式

    Args:
        directory: 待压缩的文件夹路径
        zip_file_path: 压缩后的 zip 文件路径
    """

    with zipfile.ZipFile(zip_file_path, "w", zipfile.ZIP_DEFLATED) as f:
        for root, _, files in os.walk(directory):
            for file in files:
                absolute_path: str = os.path.join(root, file)
                relative_path: str = os.path.relpath(absolute_path, directory)
                f.write(absolute_path, relative_path)


if __name__ == '__main__':
    # 要压缩的文件夹路径
    directory_to_zip = "./压缩文件123"
    # 压缩后的zip文件名
    zip_file_name = "./compressed.zip"

    zip_directory(directory_to_zip, zip_file_name)
